#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/23 下午4:34
 @Author  : tgy
 
"""

import utils
from scapy.all import *

def arp_request(ip,ifname='eth0'):
    ...
    try:
        res_raw = srp(Ether(dst='FF:FF:FF:FF:FF:FF') / ARP(op=1, hwdst='00:00:00:00:00:00', pdst=ip), timeout=1,
                      iface=ifname, verbose=False)
        if res_raw:
            res_dic = res_raw[0].res[0][1].getlayer(ARP).fields
            return res_dic['psrc'], res_dic['hwsrc']
    except Exception:
        return



if __name__ == '__main__':
    ...
    import sys
    argv_len = len(sys.argv)
    if argv_len == 1:
        print('请输入ip')
        exit(1)
    elif argv_len == 2:
        print(arp_request(sys.argv[1]))
    elif argv_len >= 3:
        print(arp_request(ip=sys.argv[1],ifname=sys.argv[2]))
